function e(e, t, n) {
    return t in e ? Object.defineProperty(e, t, {
        value: n,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : e[t] = n, e;
}

Object.defineProperty(exports, "__esModule", {
    value: !0
});

var t = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(e) {
    return typeof e;
} : function(e) {
    return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
}, n = function(e) {
    return e && e.__esModule ? e : {
        default: e
    };
}(require("../component"));

exports.default = {
    init: function() {
        var i = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {}, r = Object.assign({}, i), c = new n.default({
            scope: "$wux.filterbar",
            data: r,
            methods: {
                hide: function() {
                    if (this.removed) return !1;
                    this.removed = !0, this.setHidden();
                },
                show: function() {
                    if (this.removed) return !1;
                    this.setVisible();
                },
                onReset: function(t) {
                    var n = t.currentTarget.dataset, i = n.index, r = n.item.children.map(function(e) {
                        return Object.assign({}, e, {
                            children: e.children.map(function(e) {
                                return Object.assign({}, e, {
                                    checked: !1
                                });
                            }),
                            selected: ""
                        });
                    });
                    this.setData(e({}, "$wux.filterbar.items[" + i + "].children", r));
                },
                onConfirm: function(t) {
                    var n = t.currentTarget.dataset.index;
                    this.setData(e({}, "$wux.filterbar.items[" + n + "].visible", !1), this.onChange);
                },
                onRadioChange: function(t) {
                    var n, i = t.detail.value, r = t.currentTarget.dataset, c = r.index, a = r.item, o = r.parentIndex, s = a.children.map(function(e) {
                        return Object.assign({}, e, {
                            checked: e.value === i
                        });
                    }), u = s.filter(function(e) {
                        return e.checked;
                    }).map(function(e) {
                        return e.label;
                    }).join(",");
                    this.setData((n = {}, e(n, "$wux.filterbar.items[" + o + "].children[" + c + "].children", s), 
                    e(n, "$wux.filterbar.items[" + o + "].children[" + c + "].selected", u), n));
                },
                onCheckboxChange: function(t) {
                    var n, i = t.detail.value, r = t.currentTarget.dataset, c = r.index, a = r.item, o = r.parentIndex, s = a.children.map(function(e) {
                        return Object.assign({}, e, {
                            checked: i.includes(e.value)
                        });
                    }), u = s.filter(function(e) {
                        return e.checked;
                    }).map(function(e) {
                        return e.label;
                    }).join(",");
                    this.setData((n = {}, e(n, "$wux.filterbar.items[" + o + "].children[" + c + "].children", s), 
                    e(n, "$wux.filterbar.items[" + o + "].children[" + c + "].selected", u), n));
                },
                radioChange: function(t) {
                    var n = t.detail.value, i = t.currentTarget.dataset, r = i.index, c = i.item.children.map(function(e) {
                        return Object.assign({}, e, {
                            checked: e.value === n
                        });
                    });
                    this.setData(e({}, "$wux.filterbar.items[" + r + "].children", c), this.onChange);
                },
                checkboxChange: function(t) {
                    var n = t.detail.value, i = t.currentTarget.dataset, r = i.index, c = i.item.children.map(function(e) {
                        return Object.assign({}, e, {
                            checked: n.includes(e.value)
                        });
                    });
                    this.setData(e({}, "$wux.filterbar.items[" + r + "].children", c), this.onChange);
                },
                onClick: function(e) {
                    var t = e.currentTarget.dataset.index;
                    this.onOpenSelect(this.page.data.$wux.filterbar.items, t);
                },
                onOpenSelect: function() {
                    var n = this, i = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : [], r = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 0, c = i[r], a = i.map(function(e, i) {
                        var a = Object.assign({}, e, {
                            checked: r === i && !e.checked
                        });
                        if (e.checked) {
                            var o = n.getDifference(e.groups, c.groups);
                            a.checked = !!o.length, r === i || o.length || ("object" === t(a.children) && ([ "radio", "checkbox" ].includes(e.type) && (a.children = a.children.map(function(e) {
                                return Object.assign({}, e, {
                                    checked: !1
                                });
                            })), [ "filter" ].includes(e.type) && (a.children = a.children.map(function(e) {
                                return Object.assign({}, e, {
                                    children: e.children.map(function(e) {
                                        return Object.assign({}, e, {
                                            checked: !1
                                        });
                                    }),
                                    selected: ""
                                });
                            }))), [ "sort" ].includes(e.type) && (a.sort = void 0));
                        }
                        return [ "radio", "checkbox", "filter" ].includes(e.type) && (a.visible = r === i && !e.visible), 
                        r === i && [ "sort" ].includes(e.type) && (a.sort = "number" == typeof a.sort ? -a.sort : 1), 
                        a;
                    });
                    this.setData(e({}, "$wux.filterbar.items", a), function() {
                        [ "radio", "checkbox", "filter" ].includes(c.type) || n.onChange();
                    });
                },
                onCloseSelect: function() {
                    var e = {};
                    this.page.data.$wux.filterbar.items.forEach(function(t, n) {
                        t.checked && t.visible && (e["$wux.filterbar.items[" + n + "].visible"] = !1);
                    }), this.setData(e);
                },
                getDifference: function() {
                    var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : [], t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : [];
                    return e.filter(function(e) {
                        return t.includes(e);
                    });
                },
                resetValue: function() {
                    arguments.length > 0 && void 0 !== arguments[0] && arguments[0];
                    items.children.map(function(e) {
                        return Object.assign({}, e, {
                            checked: !1
                        });
                    });
                },
                onChange: function() {
                    var e = this.page.data.$wux.filterbar.items, t = e.filter(function(e) {
                        return e.checked;
                    });
                    "function" == typeof r.onChange && r.onChange.call(this, t, e);
                }
            }
        });
        return c.show(), c;
    }
};